﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace NDasm.Core.UI.Base
{
    public class DelegateCommand<T> : ICommand
    {
        private readonly Action<T> execute;

        public DelegateCommand(Action<T> execute)
        {
            if (execute == null)
                throw new ArgumentNullException();
            this.execute = execute;
        }

        public void Execute(object parameter)
        {
            if (parameter != null)
                execute((T)parameter);
            else
                execute(default(T));
        }

        public bool CanExecute(object parameter)
        {
            return parameter == null || parameter is T;
        }

        public event EventHandler CanExecuteChanged;
    }
}
